﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QuickORM.BLL;
using QuickORM.Entity;
using QuickORM.Common;
using Lir.Pager.Entity;
public partial class Manage_WebPages_UserInfo_UserList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            Query("1=1");
            ViewState["where"] = "1=1";
        }
    }
    #region 检索
    /// <summary>
    /// 检索
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="eventArgs"></param>
    protected void btnSelect_Click(object sender,EventArgs eventArgs)
    {
        string name = Util.querySQL(txtUserName.Value.Trim());
        string where = " 1=1 ";
        if(!string.IsNullOrEmpty(name))
        {
            where += string.Format(" AND UserName like '%{0}%'", name);
        }
        Query(where);
        ViewState["where"] = where;
    }
    #endregion
    #region 分页处理
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Query(ViewState["where"]!=null?ViewState["where"].ToString():"1=1");
    }
    #endregion
    #region 查询方法
    /// <summary>
    /// 检索条件
    /// </summary>
    /// <param name="name"></param>
    protected void Query(string where)
    {
        
        PagerInfo pager = new PagerInfo();
        pager.CurrenetPageIndex = AspNetPager1.CurrentPageIndex;
        pager.PageSize = AspNetPager1.PageSize;
        rptList.DataSource = BLLFactory<T_UserInfoManager>.Instance.FindWithPager(where, pager, "UserID", true);
        rptList.DataBind();
        AspNetPager1.RecordCount = pager.RecordCount;
    }
    #endregion
    #region 删除
    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void linkBtnDel_Click(object sender, EventArgs e)
    {
        LinkButton linkBtnDel = sender as LinkButton;
        if (linkBtnDel.CommandName == "del")
        {
            int id = Convert.ToInt32(linkBtnDel.CommandArgument);
            BLLFactory<T_UserInfoManager>.Instance.Delete(id);
            Query(ViewState["where"] != null ? ViewState["where"].ToString() : "1=1");
        }
    }
    #endregion
    #region 重置密码
    /// <summary>
    /// 重置密码
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void linkBtnPwd_Click(object sender, EventArgs e)
    {
        LinkButton linkBtnPwd = sender as LinkButton;
        if (linkBtnPwd.CommandName == "pwd")
        {
            string id =linkBtnPwd.CommandArgument;
            if(BLLFactory<T_UserInfoManager>.Instance.ChangePwd(id,QuickORM.Common.Util.SHA1("123456"))>0)
            {
                ScriptManager.RegisterClientScriptBlock(this.UpdatePanel1,this.GetType(),"","alert('密码已重置为：123456');",true);
                Query(ViewState["where"] != null ? ViewState["where"].ToString() : "1=1");
            }
            
        }
    }
    #endregion
}